package com.yztc.xiami_app.ui.user.presenter;

import com.yztc.xiami_app.ui.user.interfaces.IUserRegisterListener;
import com.yztc.xiami_app.ui.user.model.IUserModel;
import com.yztc.xiami_app.ui.user.model.UserModelImpl;
import com.yztc.xiami_app.ui.user.view.IRegisterView;

import cn.bmob.v3.datatype.BmobFile;

/**
 * Created by 周旭 on 2016/12/4.
 */

public class UserPresenterImpl implements IUserPresenter {

    private IUserModel mUserModel;
    private IRegisterView mRegisterView;
    //注册结果的回调接口,用户上传头像的回调接口
    private IUserRegisterListener listener = new IUserRegisterListener() {
        @Override
        public void uploadSuccess(BmobFile bmobFile) {
            //上传头像成功
            mRegisterView.uploadSuccess(bmobFile);
        }

        @Override
        public void uploadFailure() {
            //上传头像失败
            mRegisterView.uploadFailure();
        }

        @Override
        public void getResult(boolean isSuccess,int errorCode) {
            //返回注册结果
            mRegisterView.registerResult(isSuccess,errorCode);
        }
    };



    public UserPresenterImpl(IRegisterView mRegisterView) {
        this.mRegisterView = mRegisterView;
        mUserModel = new UserModelImpl();
    }

    @Override
    public void register(String userName, String password, String email,String phone, BmobFile userHeaderFile) {

        mUserModel.register(userName,password,email,phone,userHeaderFile,listener);
    }

    @Override
    public void saveHeaderPic(String headerPicPath) {
        mUserModel.saveHeaderPic(headerPicPath,listener);
    }
}
